﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using Project.dalSql;
using System.Web.SessionState;
using WISD.Common;

namespace WISD.CarFriend.Web.Admin.Control
{
    /// <summary>
    /// Member 的摘要说明
    /// 继承IReadOnlySessionState，就可以使用Session
    /// </summary>
    public class Member : IHttpHandler, IReadOnlySessionState
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string MemberID = NullHelper.NullProcess<string>(context.Request["MemberID"], "");
            string WebUserName = NullHelper.NullProcess<string>(context.Request["WebUserName"], "");
            string WebPwd = NullHelper.NullProcess<string>(context.Request["WebPwd"], "");
            string Name = NullHelper.NullProcess<string>(context.Request["Name"], "");
            string Sex = NullHelper.NullProcess<string>(context.Request["Sex"], "-1");
            string Birthday = NullHelper.NullProcess<string>(context.Request["Birthday"], "1888/1/1");
            string MobileTel = NullHelper.NullProcess<string>(context.Request["MobileTel"], "");
            string QQ = NullHelper.NullProcess<string>(context.Request["QQ"], "");
            string Email = NullHelper.NullProcess<string>(context.Request["Email"], "");
            string IdentityCard = NullHelper.NullProcess<string>(context.Request["IdentityCard"], "");
            string Address = NullHelper.NullProcess<string>(context.Request["Address"], "");
            string ReturnVisitDate = NullHelper.NullProcess<string>(context.Request["ReturnVisitDate"], "1888/1/1");
            string VehicleNo = NullHelper.NullProcess<string>(context.Request["VehicleNo"], "");
            string VehicleStyle = NullHelper.NullProcess<string>(context.Request["VehicleStyle"], "");
            string EngineNo = NullHelper.NullProcess<string>(context.Request["EngineNo"], "");
            string VehicleFrameNo = NullHelper.NullProcess<string>(context.Request["VehicleFrameNo"], "");
            string DriveCardNo = NullHelper.NullProcess<string>(context.Request["DriveCardNo"], "");
            string DriveCardAnnualReviewDate = NullHelper.NullProcess<string>(context.Request["DriveCardAnnualReviewDate"], "1888/1/1");
            string DriveCardGetDate = NullHelper.NullProcess<string>(context.Request["DriveCardGetDate"], "1888/1/1");
            string RideCardNo = NullHelper.NullProcess<string>(context.Request["RideCardNo"], "");
            string RideCardAnnualReviewDate = NullHelper.NullProcess<string>(context.Request["RideCardAnnualReviewDate"], "1888/1/1");
            string PurchaseDate = NullHelper.NullProcess<string>(context.Request["PurchaseDate"], "1888/1/1");
            string NextMaintenanceDate = NullHelper.NullProcess<string>(context.Request["NextMaintenanceDate"], "1888/1/1");
            string VehicleAnnualInspectionDate = NullHelper.NullProcess<string>(context.Request["VehicleAnnualInspectionDate"], "1888/1/1");
            string InsuranceNo = NullHelper.NullProcess<string>(context.Request["InsuranceNo"], "");
            string InsuranceExpirationDate = NullHelper.NullProcess<string>(context.Request["InsuranceExpirationDate"], "1888/1/1");
            string OilConsumption = NullHelper.NullProcess<string>(context.Request["OilConsumption"], "");
            string DriveKilometers = NullHelper.NullProcess<string>(context.Request["DriveKilometers"], "");
            string IsCard = NullHelper.NullProcess<string>(context.Request["IsCard"], "-1");
            string Reviser = context.Session["UserCode"].ToString();

            string action = NullHelper.NullProcess<string>(context.Request["Action"], "");
            int pageSize = NullHelper.NullProcess<int>(context.Request["PageSize"], 0);
            int pageIndex = NullHelper.NullProcess<int>(context.Request["CurrentPage"], 0);
            string condition = NullHelper.NullProcess<string>(context.Request["Condition"], "");
            string main = NullHelper.NullProcess<string>(context.Request["Main"], "");

            if (action == "Init")
            {
                context.Response.Write(BLL.OA.MemberModule.GetData(pageSize, pageIndex, condition));
                context.Response.End();
            }

            if (action == "GetOne")
            {
                context.Response.Write(BLL.OA.MemberModule.GetOne(main));
                context.Response.End();
            }

            if (action == "AddEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("MemberID", MemberID);
                dictionary.Add("WebUserName", WebUserName);
                dictionary.Add("WebPwd", WebPwd);
                dictionary.Add("Name", Name);
                dictionary.Add("Sex", Sex);
                dictionary.Add("Birthday", Birthday);
                dictionary.Add("MobileTel", MobileTel);
                dictionary.Add("QQ", QQ);
                dictionary.Add("Email", Email);
                dictionary.Add("IdentityCard", IdentityCard);
                dictionary.Add("Address", Address);
                dictionary.Add("ReturnVisitDate", ReturnVisitDate);
                dictionary.Add("VehicleNo", VehicleNo);
                dictionary.Add("VehicleStyle", VehicleStyle);
                dictionary.Add("EngineNo", EngineNo);
                dictionary.Add("VehicleFrameNo", VehicleFrameNo);
                dictionary.Add("DriveCardNo", DriveCardNo);
                dictionary.Add("DriveCardAnnualReviewDate", DriveCardAnnualReviewDate);
                dictionary.Add("DriveCardGetDate", DriveCardGetDate);
                dictionary.Add("RideCardNo", RideCardNo);
                dictionary.Add("RideCardAnnualReviewDate", RideCardAnnualReviewDate);
                dictionary.Add("PurchaseDate", PurchaseDate);
                dictionary.Add("NextMaintenanceDate", NextMaintenanceDate);
                dictionary.Add("VehicleAnnualInspectionDate", VehicleAnnualInspectionDate);
                dictionary.Add("InsuranceNo", InsuranceNo);
                dictionary.Add("InsuranceExpirationDate", InsuranceExpirationDate);
                dictionary.Add("OilConsumption", OilConsumption);
                dictionary.Add("DriveKilometers", DriveKilometers);
                dictionary.Add("IsCard", IsCard);
                dictionary.Add("Reviser", Reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                if (BLL.OA.MemberModule.AddEntity(dictionary).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "DeleteEntity")
            {
                context.Response.Write(BLL.OA.MemberModule.DeleteEntity(main));
                context.Response.End();
            }

            if (action == "EditEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("MemberID", MemberID);
                dictionary.Add("WebUserName", WebUserName);
                dictionary.Add("WebPwd", WebPwd);
                dictionary.Add("Name", Name);
                dictionary.Add("Sex", Sex);
                dictionary.Add("Birthday", Birthday);
                dictionary.Add("MobileTel", MobileTel);
                dictionary.Add("QQ", QQ);
                dictionary.Add("Email", Email);
                dictionary.Add("IdentityCard", IdentityCard);
                dictionary.Add("Address", Address);
                dictionary.Add("ReturnVisitDate", ReturnVisitDate);
                dictionary.Add("VehicleNo", VehicleNo);
                dictionary.Add("VehicleStyle", VehicleStyle);
                dictionary.Add("EngineNo", EngineNo);
                dictionary.Add("VehicleFrameNo", VehicleFrameNo);
                dictionary.Add("DriveCardNo", DriveCardNo);
                dictionary.Add("DriveCardAnnualReviewDate", DriveCardAnnualReviewDate);
                dictionary.Add("DriveCardGetDate", DriveCardGetDate);
                dictionary.Add("RideCardNo", RideCardNo);
                dictionary.Add("RideCardAnnualReviewDate", RideCardAnnualReviewDate);
                dictionary.Add("PurchaseDate", PurchaseDate);
                dictionary.Add("NextMaintenanceDate", NextMaintenanceDate);
                dictionary.Add("VehicleAnnualInspectionDate", VehicleAnnualInspectionDate);
                dictionary.Add("InsuranceNo", InsuranceNo);
                dictionary.Add("InsuranceExpirationDate", InsuranceExpirationDate);
                dictionary.Add("OilConsumption", OilConsumption);
                dictionary.Add("DriveKilometers", DriveKilometers);
                dictionary.Add("IsCard", IsCard);
                dictionary.Add("Reviser", Reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                if (BLL.OA.MemberModule.EditEntity(dictionary).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "GetMemberId")
            {
                context.Response.Write(BLL.OA.MemberModule.GetMemberId());
                context.Response.End();
            }
        }


        /// <summary>
        /// IsReusable
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}